#!/usr/bin/python
# -*- coding: utf-8 -*-

src = '../src/'
import sys
sys.path.append(src)

import lilidb

db = lilidb.lilidb()

db.create_empty_db(':memory:')

db.insert_author(db,
                     ('John Ronald Reuel Tolkien',
                      '03/01/1892',
                      '02/09/1973',
                      'Escritor e poeta inglês.'))

db.insert_author(db,
                     ('Agatha Christie',
                      '15/09/1890',
                      '12/01/1976',
                      'Romancista policial britânica.'))

db.insert_author(db,
                     ('Stephen Hawking',
                      '08/01/1942',
                      None,
                      'Físico teórico britânico.'))



for each in lilidb.get_author_by_name( db, ('Aline Tiemi Sugano',) ):
    print each



import unittest

class test_lilidb(unittest.TestCase):    
    def setUp(self):
        self.lilidb = lilidb.lilidb()
        self.create_empty_db(':memory:')
        
    def test_insert_get_author(self):
        for t in [('diogo','25/09/1984',None , 'descrição teste'),
                  ('aline','07/06/1983',None , 'mais uma descrição teste')]:
            self.lilidb.insert_author(t)

        # make sure the shuffled sequence does not lose any elements
        random.shuffle(self.seq)
        self.seq.sort()
        self.assertEqual(self.seq, range(10))

    def testchoice(self):
        element = random.choice(self.seq)
        self.assert_(element in self.seq)

    def testsample(self):
        self.assertRaises(ValueError, random.sample, self.seq, 20)
        for element in random.sample(self.seq, 5):
            self.assert_(element in self.seq)

if __name__ == '__main__':
    unittest.main()
